package com.luobu.javaee.dao;

import com.luobu.javaee.domain.DocumentSearch;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DocumentEsRepository extends ElasticsearchRepository<DocumentSearch, Long> {
    @Query("{\"bool\": {\"must\": [{\"match\": {\"docName\": \"?0\"}}]}}")
    List<DocumentSearch> findByDocNameCustom(String docName);

    @Query("{ \n" +
            "  \"bool\": { \n" +
            "    \"must\": [\n" +
            "      { \"match\": { \"docName\": \"?0\" } }\n" +
            "    ],\n" +
            "      \"filter\": [ \n" +
            "      { \"term\":  { \"archiveId\": \"?1\" } }\n" +
            "    ]\n" +
            "  }\n" +
            "} ")
    List<DocumentSearch> matchDocsInArchive(String keyword, Long ArchiveId);

    List<DocumentSearch> findByDocName(String docName);

    List<DocumentSearch> findByDocNameAndUserId(String docName, Long userId);

    void deleteByDocId(Long docId);

    void deleteByDocName(String docName);

    void deleteByUserIdAndDocName(Long userId, String docName);

    List<DocumentSearch> findByUserIdAndDocNameIn(Long userId, List<String> docName);
}